package cate.game.play.buff.h;

import cate.common.table.d.GD;
import cate.common.table.d.GDSkill;
import cate.common.util.XT;
import cate.game.play.buff.BuffHandler;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.util.FighterFilter;

import java.util.List;

/**
 * 击杀目标时给添加buff
 */
public class 击杀添加buffBH extends BuffHandler {

	private PlayCfgArgs args;
	private List<String> 技能标签;
	private byte 目标基准;
	private int 概率;
	private List<Integer> buffList;

	//技能标签=??&目标基准=1&概率=10000&buff=123
	@Override
	public void parse(String code) {
		args = new PlayCfgArgs(code);
		技能标签 = args.getStrList("技能标签");
		目标基准 = args.getByte("目标基准", GDSkill.Base.TARGET);
		概率 = args.getInt("概率", GD.W_10000);
		buffList = args.getIntList("buff");
	}

	@Override
	public void onKill(ActionCtx action, Fighter deader) {
		if (XT.isNotBlank(技能标签)) {
			if (!(action instanceof SkillActionCtx)) {
				return;
			}
			if (!((SkillActionCtx) action).getSkill().cfg.containTags(技能标签)) {
				return;
			}
		}
		if (FighterFilter.test(args, super.buff.owner, deader)) {
			Fighter target = getFighterBySrc(目标基准, super.buff.owner, deader);
			if (XT.isNotBlank(buffList)) {
				for (Integer addBuff : buffList) {
					target.buff.tryAddByTid(action, this.getBuff().owner, addBuff, 概率);
				}
			}
		}
	}
}
